//
//  ViewController.m
//  032519-友盟统计SDK
//
//  Created by 强进冬 on 2019/3/25.
//  Copyright © 2019 强进冬. All rights reserved.
//

#import "ViewController.h"
#import "UMTool.h"
#import "CanalyticsController.h"
#import "AuthorizeLoginController.h"
#import "ShareController.h"

@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray<NSDictionary *> *dataSource;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Demo";
    
//   self.tableView.contentInset = UIEdgeInsetsMake(15 - 35, 0, 0, 0);
    self.tableView.sectionHeaderHeight = 30;
    self.tableView.sectionFooterHeight = 30;
    [self.tableView registerClass:UITableViewHeaderFooterView.self forHeaderFooterViewReuseIdentifier:@"viewControllerHeader"];
    [self.tableView registerClass:UITableViewHeaderFooterView.self forHeaderFooterViewReuseIdentifier:@"viewControllerFooter"];
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    NSLog(@"%ld", self.dataSource.count);
    return self.dataSource.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return ((NSArray *)self.dataSource[section][@"rows"]).count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"viewControllerCellID" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSeparatorStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.text = self.dataSource[indexPath.section][@"rows"][indexPath.row];
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UITableViewHeaderFooterView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"viewControllerHeader"];
    header.textLabel.text = [NSString stringWithFormat:@"header - %ld", section];
    return header;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UITableViewHeaderFooterView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"viewControllerFooter"];
    header.textLabel.text = [NSString stringWithFormat:@"footer - %ld", section];
    return header;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:
            [self.navigationController pushViewController:[CanalyticsController new] animated:true];
            break;
        case 1:
            switch (indexPath.row) {
                case 0:
                    [self.navigationController pushViewController:[AuthorizeLoginController new] animated:true];
                    break;
                case 1:
                    [self.navigationController pushViewController:[ShareController new] animated:true];
                default:
                    break;
            }
            break;
        default:
            break;
    }
}

- (NSArray<NSDictionary *> *)dataSource {
    if (!_dataSource) {
        _dataSource = @[
                        @{
                            @"rows" :
                                @[
                                    @"统计",
                                    ],
                            },
                        
                        @{
                            @"rows" : @[
                                    @"第三方登录",
                                    @"分享到第三方平台",
                                    ],
                            },
                        
                        
                        ];
    }
    return _dataSource;
}

@end
